package com.turingitclub.yutian;

import java.util.*;

/**
 * <pre>
 *
 * </pre>
 *
 * @author zhoulei
 * @create 2020-03-14 20:02
 **/
public class Room {
    /**
     * 对象属性students
     */
    private List<Student> students = new ArrayList<Student>();

    public Room() {
        // students = new ArrayList<Student>();
    }

    public List<Student> getStudents(){
        System.out.println("students:" + students.toString());
        return students;
    }

    public void createStudent(String name, Double temperature) {
        Student stu2 = new Student(name);
        stu2.setTemperature(temperature);
        System.out.println(stu2.getName() + ": " +  stu2.getTemperature());
        students.add(stu2);
    }

    public void println(List<Student> students) {
        int size = students.size();
        int i = 0;
        System.out.println("遍历输出所有学生信息：" );
        for(i = 0; i<size; i++){ // 0~size-1,逐步递增1
            // 获取students中索引为i的元素
            Student stu = students.get(i);
            // System.out.println(stu)等价于System.out.println(stu.toString());
            // 所有对象都继承了Object方法
            System.out.println(stu);
        }
    }

    public void hot(){
        // 查找学生中发烧的是谁
        int size = students.size();
        int i = 0;
        System.out.println("正常温度：" + Student.getNormalTemperature()); // 调用类的静态方法
        System.out.println("查找学生中发烧的是谁：" );
        for(i = 0; i<size; i++){ // 0~size-1,逐步递增1
            // 获取students中索引为i的元素
            Student stu = students.get(i);
            if(stu.getTemperature() > Student.getNormalTemperature()){
                System.out.println(stu);
            }
        }
    }

    public void firstHot() {
        int size = students.size();
        int i = 0;
        System.out.println("查找学生中第一个发烧的是谁");
        for(i = 0; i<size; i++){ // 0~size-1,逐步递增1
            // 获取students中索引为i的元素
            Student stu = students.get(i);
            if(stu.getTemperature() > Student.getNormalTemperature()){
                System.out.println(stu);
                break; // 本次循环结束，且for轮询也结束
                // continue; // 本次循环结束，进入下次循环，for轮询未结束
                // System.out.println("123");
            }
        }
    }
}
